package com.jxpanda.spring.module.auth.core.authentication.token;

import com.jxpanda.spring.module.auth.endpoint.OAuth2Request;
import lombok.Getter;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.oauth2.client.registration.ClientRegistration;


@Getter
public class CollaborativeAuthenticationToken extends AbstractAuthenticationToken {

    private final OAuth2Request oAuth2Request;

    private final ClientRegistration clientRegistration;

    private Object credentials;

    public CollaborativeAuthenticationToken(OAuth2Request oAuth2Request, ClientRegistration clientRegistration) {
        super(null);
        this.oAuth2Request = oAuth2Request;
        this.clientRegistration = clientRegistration;
        this.credentials = oAuth2Request.getCredentials();
    }

    @Override
    public String getName() {
        return oAuth2Request.getUsername();
    }

    @Override
    public Object getCredentials() {
        return this.credentials;
    }

    @Override
    public void eraseCredentials() {
        super.eraseCredentials();
        this.credentials = "";
    }

    @Override
    public Object getPrincipal() {
        // 这个对象是不存在principal的，因为这个对象处理的是入参，此时还未认证，也还未获取用户信息的
        return null;
    }

}
